import pygame
import os

class SpritesClass:
    def __init__(self):
        self.DEFAULT_PATH = os.path.join(os.curdir, "data","sprites")
        self.SPRITES_LIST_PATH = os.path.join(self.DEFAULT_PATH, "spritelist.dat")
        self.sprites_surfaces = {}


    def load_sprites(self):
        for root, dirs, files in os.walk(self.DEFAULT_PATH):
            for f in files:
                if f[-3:] == "png":
                    try:
                        new_surface = pygame.image.load(os.path.join(root,f)).convert()
                        new_surface.set_colorkey((255,0,255),0)
                        
                    except: 
                        print "Error: failed to load - %s" % f
                        continue

                    realname = os.path.join(root.split(self.DEFAULT_PATH)[1][1:], f[:-4])
                    self.sprites_surfaces[realname] = new_surface


    def get_sprite(self, *name):
        realname = os.path.join(*name)
        try:
            return self.sprites_surfaces[realname]
        except:
            print "Error: sprite not found - %s" % realname
            raise SystemExit



Sprites = SpritesClass()
